package com.sali.b_design_pattern.i_iterator_pattern.service.impl;

import com.sali.b_design_pattern.i_iterator_pattern.pojo.Student;

import java.util.List;

public class ConcreteStudentIterator implements java.util.Iterator<Student> {

    private List<Student> students;

    private int currentIndex = 0;


    public ConcreteStudentIterator(List<Student> students) {
        this.students = students;
    }


    @Override
    public boolean hasNext() {
        return currentIndex < students.size();
    }

    @Override
    public Student next() {
        if (hasNext()) {
            Student student = students.get(currentIndex);
            currentIndex++;
            return student;
        }
        return null;
    }
}
